package com.dzk.cp.c11x5.index.q2.kd.yl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.SpringBeanUtils;

public abstract class Q2KDnYLIndex extends BaseC11x5Index {
	
	private int kd;
	
	protected Q2KDnYLIndex setParams(int code, int num, int unit, int kd) {
		super.setParams(code, num, unit);
		this.kd = kd;
		return this;
	}

	@Override
	public Map<?, Integer> index() {
		Map<Integer, Integer> resultMap = new LinkedHashMap<Integer, Integer>();
		int n = getLastestNum();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(n);
		int i = -1, j = 0, k = 0;
		for (; k < n; k++) {
			R5 r5 = r5s.get(k);
			int tmp = r5.getN1() - r5.getN2();
			if (tmp == kd || tmp == -kd) {
				resultMap.put(++j, k - i - 1);
				i = k;
			}
		}
		resultMap.put(++j, k - 1 - i);
		return resultMap;
	}
	
	public static Q2KDnYLIndex getInstance(int code, int num, int unit, int kd) {
		switch (kd) {
		case 1:
			return new Q2KD1YLIndex().setParams(code, num, unit, kd);
		case 2:
			return new Q2KD2YLIndex().setParams(code, num, unit, kd);
		case 3:
			return new Q2KD3YLIndex().setParams(code, num, unit, kd);
		case 4:
			return new Q2KD4YLIndex().setParams(code, num, unit, kd);
		case 5:
			return new Q2KD5YLIndex().setParams(code, num, unit, kd);
		case 6:
			return new Q2KD6YLIndex().setParams(code, num, unit, kd);
		case 7:
			return new Q2KD7YLIndex().setParams(code, num, unit, kd);
		case 8:
			return new Q2KD8YLIndex().setParams(code, num, unit, kd);
		case 9:
			return new Q2KD9YLIndex().setParams(code, num, unit, kd);
		case 10:
			return new Q2KD10YLIndex().setParams(code, num, unit, kd);
		default:
			return null;
		}
	}

}

class Q2KD1YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 10;
	}
	
}

class Q2KD2YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 9;
	}
	
}

class Q2KD3YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 8;
	}
	
}

class Q2KD4YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 7;
	}
	
}

class Q2KD5YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 6;
	}
	
}

class Q2KD6YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 5;
	}
	
}

class Q2KD7YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 4;
	}
	
}

class Q2KD8YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 3;
	}
	
}

class Q2KD9YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 2;
	}
	
}

class Q2KD10YLIndex extends Q2KDnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 1;
	}
	
}
